package com.njust.controller;

import com.njust.common.ServerRespone;
import com.njust.service.TableService;
import com.njust.utils.DateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author zjwpro@foxmail.com
 * @date 2018/3/11 下午10:49
 */
@RestController
@Api("行车报表")
@RequestMapping("/table")
@Slf4j
public class TableController {


    @Autowired
    private TableService tableService;
    /**
     * @param pre 开始时间0点 到24点的过车情况
     * @param pagenumber
     * @param pagesize
     * @return
     */
    @GetMapping("/report/{pre}/{pagenumber}/{pagesize}")
    @ApiOperation(value="行车报表列车综合数据")
    public ServerRespone showDataByTable(@PathVariable("pre")String pre, @PathVariable(name = "pagenumber")Integer pagenumber,
                                    @PathVariable(name ="pagesize")Integer pagesize) throws ParseException {
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyyMMdd000000");
        Date startTime=DateUtil.String2Date(simpleDateFormat.format(new Date()));
        long time=startTime.getTime()+86400000;
        Date endTime=new Date(time);
        ServerRespone serverRespone = tableService.showDataByTable(startTime, endTime, pagenumber, pagesize);
        return serverRespone;
    }
}
